﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Configuration;
using Communergy.Repository;

namespace CommunergyWebApplication.services
{
    // NOTE: If you change the class name "CommunergyUploadService" here, you must also update the reference to "CommunergyUploadService" in Web.config.
    public class CommunergyUploadService : ICommunergyUploadService
    {

        #region ICommunergyUploadService Members

        public void UploadRealtimeReadings(string meterId, DateTime uploadDateTime, List<Communergy.Common.RealtimeEnergyReading> realtimeEnergyReadings)
        {
            var connString = AzureLibrary.ConfigurationHelper.EntityFrameworkConnectionString;
            EntityAutomaticRepository repository = new EntityAutomaticRepository(connString); 

            repository.Insert_ElectricityRealtime(meterId, realtimeEnergyReadings);

        }

        #endregion

        #region ICommunergyUploadService Members


        public void UploadHourlyReadings(string meterId, DateTime uploadDateTime, List<Communergy.Common.HistoricalEnergyReading> hourlyEnergyReadings)
        {
            var connString = AzureLibrary.ConfigurationHelper.EntityFrameworkConnectionString;
            EntityAutomaticRepository repository = new EntityAutomaticRepository(connString);
            repository.Insert_ElectricityHourly(meterId, hourlyEnergyReadings);
        }

        public void UploadDailyReadings(string meterId, DateTime uploadDateTime, List<Communergy.Common.HistoricalEnergyReading> dailyEnergyReadings)
        {
            var connString = AzureLibrary.ConfigurationHelper.EntityFrameworkConnectionString;
            EntityAutomaticRepository repository = new EntityAutomaticRepository(connString);
            repository.Insert_ElectricityDaily(meterId, dailyEnergyReadings);
        }

        public void UploadMonthlyReadings(string meterId, DateTime uploadDateTime, List<Communergy.Common.HistoricalEnergyReading> monthlyEnergyReadings)
        {
            var connString = AzureLibrary.ConfigurationHelper.EntityFrameworkConnectionString;
            EntityAutomaticRepository repository = new EntityAutomaticRepository(connString);
            repository.Insert_ElectricityMonthly(meterId, monthlyEnergyReadings);
        }

        #endregion
    }
}
